import "core-js/stable";
import "regenerator-runtime/runtime";
import Vue from "vue";
import App from "./App.vue";
import "../src/style/global.scss";
import ElementUI from "element-ui";
import router from "../src/route/index";
import "element-ui/lib/theme-chalk/index.css";
import "./assets/download (4)/font_3854970_ks41mau3ncs/iconfont.css";
import store from "./store/index";
Vue.use(ElementUI);
Vue.config.productionTip = false;
Vue.directive("highlight", function (el) {
  let blocks = el.querySelectorAll("pre code");
  blocks.forEach((block) => {
    hljs.highlightBlock(block);
  });
});
new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
// 权限校验
const white = ["mesboard"];
router.beforeEach(function (to, from, next) {
  // console.log(to);
  if (white.includes(to.name) && !localStorage.getItem("token")) {
    ElementUI.Message({
      title: "错误",
      message: "没有登录哦，请您登录后在尝试",
      type: "error",
      duration: 700,
    });
    setTimeout(function () {
      store.dispatch("user/setshowlogin", true);
    }, 1000);
    return next("/");
    //token是没有登录让其跳转到登录页面
  } else {
    return next();
  }
});
